<?php


namespace App\Http\Controllers\Admin;
use App\Http\Controllers\BaseController;
use App\Models\AnimalCatMatch;
use App\Models\Circle;
use Illuminate\Http\Request;

class AnimalCatMatchController extends BaseController
{
    protected $model = AnimalCatMatch::class;
    /**
     * 列表
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request) {
        $input = $request->input();
        $search = ['start_at' => '', 'end_at' => '', 'title' => ''];
        $list = AnimalCatMatch::apply($search, $input)->orderBy("id", "desc")
            ->paginate(per_page());
        foreach ($list as $item) {
            $arr_circle_id = $item->rec_circle_ids ? explode(",", $item->rec_circle_ids) : [];
            $item->circle = Circle::select('id', 'title')->whereIn('id', $arr_circle_id)->get();
        }
        return $this->paginate($list);
    }

}

